﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using SdlDotNet.Graphics;
using NielsRask.K242.Core;

namespace RenderTest1
{
	class BuildingLayer : LayerBase
	{
		Size size;
		Surface surface;
		Asteroid asteroid;

		IsoEngine isoEngine;
		SurfaceCollection tiles;

		public BuildingLayer( Size size, Asteroid asteroid )
		{
			this.surface = new Surface( size );
			surface.Fill( Color.Black );
			surface.TransparentColor = Color.Black;
			surface.Transparent = true;
			this.asteroid = asteroid;
			this.size = size;
			isoEngine = new IsoEngine( 24, 48, @"..\..\Data\48x96\MouseMap.gif", new Point( 200, 0 ) );
			tiles = new SurfaceCollection();
			tiles.Add( new Surface( @"..\..\Data\48x96\ColonyHQ.bmp" ) );	// 0
			tiles.Add( new Surface( @"..\..\Data\48x96\Energy1.bmp" ) );	// 1
			tiles.Add( new Surface( @"..\..\Data\48x96\Food1.bmp" ) );		// 2
			tiles.Add( new Surface( @"..\..\Data\48x96\Housing1.bmp" ) );	// 3
            tiles.Add(new Surface(@"..\..\Data\48x96\Water1.bmp"));		// 4
			tiles.Add( new Surface( @"..\..\Data\48x96\Shipyard.bmp" ) );		// 5
			tiles.Add( new Surface( @"..\..\Data\48x96\Weapons1.bmp" ) );		// 6
			//tiles.Add( new Surface( @"..\..\Data\48x96\Terrain3.bmp" ) );
			tiles.TransparentColor = Color.Black;
			tiles.Transparent = true;

		}
		public override bool RegisterClick( SdlDotNet.Input.MouseButtonEventArgs e )
		{
			return false;
			// return base.RegisterClick();
		}

		public override Surface RenderSurface()
		{
			surface.Fill( Color.Black );


			for ( int i = 0; i < asteroid.Colony.Buildings.GetLength( 0 ); i++ )
			{
				for ( int j = 0; j < asteroid.Colony.Buildings.GetLength( 1 ); j++ )
				{
					Point p = isoEngine.Diamond_TilePlotter( new Point( i, j ) );
					if ( asteroid.Colony.Buildings[i, j] != null )
					{
						switch ( asteroid.Colony.Buildings[i, j].Type )
						{
							case BuildingType.CommandCenter:
								surface.Blit( tiles[0], p );
								break;
							case BuildingType.Energy1:
								surface.Blit( tiles[1], p );
								break;
							case BuildingType.Food1:
								surface.Blit( tiles[2], p );
								break;
							case BuildingType.Housing1:
								surface.Blit( tiles[3], p );
								break;
                            case BuildingType.Water1:
                                surface.Blit(tiles[4], p);
                                break;
							case BuildingType.Shipyard:
								surface.Blit( tiles[ 5 ], p );
								break;
							case BuildingType.WeaponsFactory:
								surface.Blit( tiles[ 6 ], p );
								break;
						}
					}
				}
			}
			//surface.Update();
			//surface.refr
			return surface;
		}
	}
}
